<?php /* УТФ-8:fix */

class SPIcontroller__captcha extends SPIcontroller__dummy
{
    private $SESSION_CAPTCHA_VARNAME = 'SPI::captcha::value';

    public function set( $is_verbose = false )
    {
        if( $is_verbose === true )
        {
            $this->close();
        }

        $captcha_value = SPI::I('session')->get_var( $this->SESSION_CAPTCHA_VARNAME );

        if( ! $captcha_value )
        {
            $captcha_value = rand(100,999).rand(10,99);
            SPI::I('session')->set_var( $this->SESSION_CAPTCHA_VARNAME, $captcha_value );
        }

        return true;
    }

    public function get()
    {
        return SPI::I('session')->get_var( $this->SESSION_CAPTCHA_VARNAME );
    }

    public function reset()
    {
        $this->close();
        $this->set();
        return true;
    }

    public function close()
    {
        SPI::I('session')->set_var( $this->SESSION_CAPTCHA_VARNAME, null );
        return true;
    }

    public function get_image_source()
    {
        return rtrim( SPIcfg::$hostnames['base'], '/' ) . SPIcfg::$dir['pubsite_root'] . SPIcfg::$util['captcha']['source'] . '?build'.rand();
    }
}
